﻿/* * Write a program that finds all prime numbers in the range [1...10 000 000]. 
 * * Use the sieve of Eratosthenes algorithm (find it in Wikipedia).
 */



using System;

class PrintPrimeSieveofEratosthenes
{
    static void Main()
    {
        //Let there be Light & shit

        //Max is the last number we check, after this we use the Sieve of Erathosthenes algo to change the value
        //of some of the array members to false (after being initialized as true in the first place)
        int Max = 10000000;
        bool[] BS = new bool[Max];
        for (int i = 2; i < Max; i++) BS[i] = true; //initialize all as true

        for (int i = 2; i < Math.Sqrt(Max); i++)
        {
            if (BS[i] == true)
            {
                int a = 0;
                for (long j = 2*i; j < Max; j += i) BS[j] = false; //change value
            }
        }

        for (int i = 0; i < Max; i++) if (BS[i] == true) Console.WriteLine(i);

  
    }
}
